﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JustTank
{
    public class Tank : MovingObject
    {
        public Tank(MatrixCoords topLeft)
            : base(topLeft, GetTankBody(TankDirection.Up), new MatrixCoords(0,0))
        { 
        }

        static protected char[,] GetTankBody(TankDirection direction)
        {
            char[,] body;

            switch (direction)
            {
                case TankDirection.Left:
                    body = new char[1, 2] { { '<', '#' } };
                    break;
                case TankDirection.Down:
                    body = new char[2, 1] { { '#' }, { '\u25BC' } };
                    break;
                case TankDirection.Right:
                    body = new char[1, 2] { { '#', '>' } };
                    break;
                case TankDirection.Up:
                    body = new char[2, 1] { { '\u25B2' }, { '#' } };
                    break;
                default:
                    body = null;
                    break;
            }

            return body;
        }

        public TankDirection GetTankDirection(MatrixCoords speed)
        {
            if (speed.Equals(new MatrixCoords(1, 0)))
            {
                return TankDirection.Down;
            }
            else if (speed.Equals(new MatrixCoords(-1, 0)))
            {
                return TankDirection.Up;
            }
            else if (speed.Equals(new MatrixCoords(0, 1)))
            {
                return TankDirection.Right;
            }
            else if (speed.Equals(new MatrixCoords(0, -1)))
            {
                return TankDirection.Left;
            }
            else
            {
                return TankDirection.Up;
            }
        }

        public override string GetCollisionGroupString()
        {
            return TankBot.CollisionGroupString;
        }

        public override bool CanCollideWith(string otherCollisionGroupString)
        {
            return otherCollisionGroupString == "playerBullet" || otherCollisionGroupString == "indestrBlock";
        }

        public override void RespondToCollision()
        {
            this.IsDestroyed = true;
        }

    }
}
